package com.ymatou.auth.testcase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.auth.parameter.DeviceAuthStatusRequestDtoBean;
import com.ymatou.auth.parameter.IpAreaAuthStatusRequestDtoBean;
import com.ymatou.auth.parameter.LoginAuthBean;
import com.ymatou.auth.service.DeviceAuthStatusRequestDtoCall;
import com.ymatou.auth.service.IpAreaAuthStatusRequestDtoCall;
import com.ymatou.auth.service.LoginAuthCall;
import com.ymatou.iapi.deviceid.parameter.SaveBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.data.LoginSafeConfiguration;
import com.ymttest.business.service.AuthCallService;
import com.ymttest.business.service.DeviceidCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.UserCallService;
import com.ymttest.database.mongo.MongoLoginHistoryWapper;
import com.ymttest.database.mongo.ULC201406Bean;
import com.ymttest.database.mongo.ULC201406Wapper;
import com.ymttest.database.mongo.UserTokenWapper;
import com.ymttest.database.mongo.YmatouBlacklistUserWapper;
import com.ymttest.database.sqlwapper.LoginHistoryWapper;
import com.ymttest.database.sqlwapper.UserSafeWapper;
import com.ymttest.database.sqlwapper.YmtUsersWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 登入认证 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_LoginAuth {
	private static LoginAuthBean lab;
	private static LoginAuthCall lac;
	private UserSafeWapper authWapper;
	private ULC201406Wapper userWapper;
	private UserTokenWapper userTokenWapper;
	private static MongoLoginHistoryWapper mloginHistoryWapper;
	private static YmatouBlacklistUserWapper ymtblacklistuserWapper;
	private static boolean DELETELOGINHISTORY = true;

	@BeforeClass
	public static void setUp() throws Exception {
		Logger.createResultFile("登入认证");
		mloginHistoryWapper = new MongoLoginHistoryWapper();
		ymtblacklistuserWapper = new YmatouBlacklistUserWapper();
	}

	@Before
	public void caseUp() throws Exception {
		lab = new LoginAuthBean();
		lac = new LoginAuthCall();
		authWapper = new UserSafeWapper();
		userWapper = new ULC201406Wapper();
		// blackLisWapper = new IpLockStatusRequestDtoMongoWapper();
		// mloginHistoryWapper=new MongoLoginHistoryWapper();
		// ymtblacklistuserWapper=new YmatouBlacklistUserWapper();
		userTokenWapper = new UserTokenWapper();
	}

	@AfterClass
	public static void tearDown() throws Throwable {
		Logger.generateResult(lac.getOpurl());

	}

	@After
	public void caseDown() throws Throwable {
		Logger.end();
		// userWapper.close();
		// blackLisWapper.close();
		// authWapper.close();
		// mloginHistoryWapper.close();
		// ymtblacklistuserWapper.close();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_001() {
		Logger.start(true, "注册用户第一次在PC端登陆，登入认证成功");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			//
			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("mainsite");
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(phone, lac.getUserData().getLoginMobile(), "验证UserName");
			Logger.verifyNotNull(AccessToken, "验证AccessToken");
			Logger.verifyEquals(UserId, lac.getUserData().getUserId(), "验证UserId");
			Logger.verifyEquals(UserName.toLowerCase(), lac.getUserData().getLoginId().toLowerCase(), "验证登陆ID");
			Logger.verifyEquals(email.toLowerCase(), lac.getUserData().getLoginMail().toLowerCase(), "验证登录邮箱");
			Logger.verifyEquals(AccessToken, lac.getUserData().getSign(), "验证Token信息");
			Map<String, Object> info = authWapper.getIPAuthByUserIdAndArea(UserId, null, null, null);
			Logger.verifyEquals(String.valueOf(UserId), info.get("UserId").toString(), "验证UserId信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_LoginAuth_002() {
		Logger.start(false, "输入错误LoginId失败");
		try {
			lab.setLoginId("nobody1");
			lab.setPas("123456a");
			lab.setClientIp(TestDataManager.getRandomIp());
			lac.setData(lab);
			lab.setSourceType("MainSite");
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(ECode.AUTH_WRONG_USERNAME_PWD, lac.getMsg(), "验证Msg信息");
			Logger.verifyEquals("LoingIdOrPasError", new JSONObject(lac.getString("Result")).get("Code"), "验证Code信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_LoginAuth_003() {
		Logger.start(false, "输入错误项Pas失败");
		try {
			lab.setLoginId("15216713145");
			lab.setPas("12345");
			lab.setClientIp(TestDataManager.getRandomIp());
			lac.setData(lab);
			lab.setSourceType("MainSite");
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(ECode.AUTH_WRONG_USERNAME_PWD, lac.getMsg(), "验证Msg信息");
			Logger.verifyEquals("LoingIdOrPasError", new JSONObject(lac.getString("Result")).get("Code"), "验证Code信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	@Ignore // 接口变动，被后面的case替换
	public void Tc_LoginAuth_004() {
		Logger.start(false, "多次登入认证加入黑名单");
		try {
			for (int i = 0; i <= 9; i++) {
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId("test007");
				lab.setPas("123456a");
				lab.setClientIp(TestDataManager.getRandomIp());
				lab.setSourceType("MainSite");
				lac.setData(lab);
				lac.callService();
			}
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
//	@Ignore // 接口变动，被后面的case替换
	public void Tc_LoginAuth_005() {
		Logger.start(false, "多次登入同ip认证加入黑名单");
		try {
			for (int i = 0; i <= 11; i++) {
				new UserCallService();
				com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean urb = JUserCallService.initUserRegisterInfoRequestDtoBean();
				UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
				Integer UserId = uc.getUserid();
				String AccessToken=uc.getAccessToken();
				
				String UserName = urb.getLoginMobile();
				String ip=urb.getClientIp();
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(UserName);
				lab.setPas("123456a");
				lab.setClientIp("173.16.100.1");
				lab.setSourceType("MainSite");
				lac.setData(lab);
				lac.callService();
			}
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	@Ignore
	// stg验证用，本地不运行
	public void Tc_LoginAuth_006() {
		Logger.start(true, "白名单多次登入认证");
		try {
			for (int i = 0; i <= 20; i++) {
				// Map UserMap = new UserCallService().registerByMobile();
				String UserName = TestDataManager.getPhoneNum();
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(UserName);
				lab.setPas("123456a");
				lab.setClientIp("116.228.41.2");
				lab.setSourceType("MainSite");
				lac.setData(lab);
				lac.callService();
			}
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	// case 无意义 待确认
	public void Tc_LoginAuth_007() {
		Logger.start(true, "登入认证成功");
		try {
			// UserId":20225153,"LoginId":"autotest_ubammm00ef",
			int UserId = 20225153;
			String UserName = "autotest_ubammm00ef";
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("MainSite");
			lac.setData(lab);
			lab.setClientIp(TestDataManager.getRandomIp());
			lac.callService();
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(UserName, lac.getUserData().getLoginId().toLowerCase(), "验证UserName");
			HashMap m = new HashMap();
			m.put("Uid", UserId);
			List<Map> list = new LoginHistoryWapper().selectTokenHistoryByUid(m);
			Logger.verifyEquals(true, list.size() > 0, "验证Ymt_TokenHistory表记录");
			// Logger.verifyNotNull(AccessToken, "验证AccessToken");
			Logger.verifyEquals(UserId, lac.getUserData().getUserId(), "验证UserId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	/***************** 用于IP区域和设备的认证测试 ******************/

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_008() {
		Logger.start(true, "常用设备登陆(即已认证过的设备), 登陆成功");
		try {
			int userId = 913;
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);

			String deviceId = "normalIOS";
			Map<String, Object> authDevice = authWapper.getDeviceAuthByUserIdAndDeviceId(userId, deviceId).get(0);
			Logger.verifyNotNull(authDevice, "验证设备已认证过");

			Logger.comment("登陆此用户");
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp("1.1.7.1");
			lab.setSourceType("app");
			lab.setDeviceId(deviceId);
			lab.setClientId("aaaa");
			lac.setData(lab);
			lac.callService();

			Logger.verifyEquals("true", lac.getString("Success"), "验证登陆成功");
			Logger.verifyEquals(userId, lac.getUserData().getUserId(), "验证用户ID");
			Logger.verifyEquals(user.gettPas(), lac.getUserData().getTradingPassword(), "验证交易密码");
			Logger.verifyEquals(user.getlBills().getLoginId().toLowerCase(), lac.getUserData().getLoginId().toLowerCase(), "验证登陆ID");
			Logger.verifyEquals(user.getlBills().getEmail(), lac.getUserData().getLoginMail().toLowerCase(), "验证邮箱");
			Logger.verifyEquals(user.getlBills().getMobile(), lac.getUserData().getLoginMobile(), "验证手机");

			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.verifyEquals(userToken.get("sId"), lac.getUserData().getSign(), "验证Token信息");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore // 被后面的case替换
	public void Tc_LoginAuth_009() {
		Logger.start(true, "常用IP区域登陆（已认证过的Ip区域）, 登陆成功");
		try {
			String ip = "2.2.1.3";
			int userId = 968;
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);

			Logger.comment("登陆此用户");
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp(ip);
			lab.setSourceType("mainsite");
			lac.setData(lab);
			lac.callService();

			Logger.verifyEquals("true", lac.getString("Success"), "验证登陆成功");
			Logger.verifyEquals(userId, lac.getUserData().getUserId(), "验证用户ID");
			Logger.verifyEquals(user.gettPas(), lac.getUserData().getTradingPassword(), "验证交易密码");
			Logger.verifyEquals(user.getlBills().getLoginId().toLowerCase(), lac.getUserData().getLoginId().toLowerCase(), "验证登陆ID");
			Logger.verifyEquals(user.getlBills().getEmail(), lac.getUserData().getLoginMail().toLowerCase(), "验证邮箱");
			Logger.verifyEquals(user.getlBills().getMobile(), lac.getUserData().getLoginMobile(), "验证手机");

			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.verifyEquals(userToken.get("sId"), lac.getUserData().getSign(), "验证Token信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	// 修改配置文件limit 不然6次会优先提示limit
	// <add key ="LoginIdCountLimitTimeSpan" value ="00:01:00"/>
	// <add key ="LoginIdLimit" value="6"/>
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_LoginAuth_010() {
		Logger.start(false, "PC端10分钟内登陆密码错误" + LoginSafeConfiguration.PC_LOGINPAS_CHECKSPEC + "次，提示需要身份验证");
		try {
			com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean urb = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer UserId = uc.getUserid();
			String AccessToken=uc.getAccessToken();
			
			String UserName = urb.getLoginMobile();
			String ip=urb.getClientIp();
			
			String loginid = urb.getLoginId();

			Logger.comment("前置条件准备");
			Logger.comment("如果ip（" + ip + "）已进黑名单，则删除，并且删除其近一天的历史登陆记录");
			checkIpLoginHistory(ip, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			Logger.comment("删除用户的历史登陆记录，以免对场景产生影响");
			checkLoginIDLoginHistory(UserId, loginid, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));

			Logger.comment("使用同一IP同一用户连续进行错误密码" + LoginSafeConfiguration.PC_LOGINPAS_CHECKSPEC + "次登陆");
			for (int i = 0; i < LoginSafeConfiguration.PC_LOGINPAS_CHECKSPEC; i++) {
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(loginid);
				lab.setClientIp(ip);
				lab.setSourceType("mainsite");
				lab.setPas("123");
				lac.setData(lab);
				lac.callService();
				Logger.verifyEquals("false", lac.getString("Success"), "验证登陆失败");
				// Logger.verifyEquals("用户名或登录密码错误", lac.getMsg(), "验证登陆信息");
				// Logger.verifyEquals("LoingIdOrPasError", new
				// JSONObject(lac.getString("Result")).get("Code"), "验证Code信息");
			}

			Logger.comment("开始用正确的密码登陆");
			lab = new LoginAuthBean();
			lac = new LoginAuthCall();
			lab.setLoginId(loginid);
			lab.setClientIp(ip);
			lab.setSourceType("mainsite");
			lab.setPas("123456a");
			lac.setData(lab);
			lac.callService();
			if (lac.getString("LastErrorMessage").equals("登录频繁请休息会")) {
				throw new Exception("未跑到风控认证,登入次数限制拦截");
			} else {
				LoginSafeConfiguration.checkLoginStatus(lac);
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	// 修改配置 <add key="backlistloginfail" value="10" />
	// <add key ="LoginIdLimit" value="10"/>
	@Ignore
	public void Tc_LoginAuth_011() {
		Logger.start(false, "App端10分钟内登陆密码错误6次，提示需要身份验证");
		try {
			com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean urb = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer UserId = uc.getUserid();
			String AccessToken=uc.getAccessToken();
			
			String UserName = urb.getLoginMobile();
			String ip=urb.getClientIp();
			
			String loginid = urb.getLoginId();
			String deviceId = TestDataManager.getRandomUUID().toString();

			Logger.comment("前置条件准备");
			Logger.comment("如果设备（" + deviceId + "）已进黑名单，则删除");
			checkDeviceLoginHistory(deviceId, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			Logger.comment("删除用户的历史登陆记录，以免对场景产生影响");
			checkLoginIDLoginHistory(UserId, UserName, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));

			Logger.comment("使用同一设备同一用户连续进行错误密码" + LoginSafeConfiguration.APP_LOGINPAS_CHECKSPEC + "次登陆");
			for (int i = 0; i < LoginSafeConfiguration.APP_LOGINPAS_CHECKSPEC; i++) {
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(UserName);
				lab.setClientIp(ip);
				lab.setSourceType("app");
				lab.setPas("123");
				lab.setDeviceId(deviceId);
				lab.setClientId(deviceId);
				lac.setData(lab);
				lac.callService();
				Logger.verifyEquals("false", lac.getString("Success"), "验证登陆失败");
				// Logger.verifyEquals("用户名或登录密码错误", lac.getMsg(), "验证登陆信息");
				// Logger.verifyEquals("LoingIdOrPasError", new
				// JSONObject(lac.getString("Result")).get("Code"), "验证Code信息");
			}

			Logger.comment("开始用正确的密码登陆");
			lab = new LoginAuthBean();
			lac = new LoginAuthCall();
			lab.setLoginId(UserName);
			lab.setClientIp(ip);
			lab.setSourceType("app");
			lab.setPas("123456a");
			lab.setDeviceId(deviceId);
			lab.setClientId(deviceId);
			lac.setData(lab);
			lac.callService();
			if (lac.getString("LastErrorMessage").equals("登录频繁请休息会")) {
				throw new Exception("未跑到风控认证,登入次数限制拦截");
			} else {
				LoginSafeConfiguration.checkLoginStatus(lac);
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_LoginAuth_012() {
		Logger.start(false, "某个IP在1分内连续进行" + LoginSafeConfiguration.IP_LOGIN_SUCCESS_LIMIT + "次的登录成功记录，提示需要身份验证");
		try {
			if (LoginSafeConfiguration.IP_LOGIN_SUCCESS_LIMIT > 0) {
				List<Map<String, Object>> authIPArea = authWapper.getIPAuthData(200, YMTDateUtil.getBeforeOrNextDay(-90), "China", "Fujian");
				if (authIPArea == null) {
					Assert.fail("没有测试数据");
				}
				String ip = "1.0.3.255";// TestDataManager.getRandomIp();//随机获取Ip(China,
										// Fujian)
				Logger.comment("删除IP黑名单和历史登陆数据(如果存在)");
				checkIpLoginHistory(ip, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));

				Logger.comment("用同一IP不同的用户进行正确登陆" + LoginSafeConfiguration.IP_LOGIN_SUCCESS_LIMIT + "次");
				for (int j = 0; j <= LoginSafeConfiguration.IP_LOGIN_SUCCESS_LIMIT; j++) {
					if (j == LoginSafeConfiguration.IP_LOGIN_SUCCESS_LIMIT) {
						Thread.sleep(1000);
					}
					ULC201406Bean user = userWapper.getULCInfoByUid((Integer) authIPArea.get(j).get("UserId"));
					userWapper.updatePwdByUid(user.getuId());
					userWapper.unlockUserByUid(user.getuId());
					lab = new LoginAuthBean();
					lac = new LoginAuthCall();
					lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
					lab.setClientIp(ip);
					lab.setSourceType("mainsite");
					lab.setPas("123456a");
					lac.setData(lab);
					lac.callService();
				}
				Thread.sleep(1000);
				Logger.comment("进行第" + (LoginSafeConfiguration.IP_LOGIN_SUCCESS_LIMIT + 1) + "次登陆");
				int userId = (Integer) authIPArea.get(2).get("UserId");
				ULC201406Bean user = userWapper.getULCInfoByUid(userId);
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
				lab.setClientIp(ip);
				lab.setSourceType("mainsite");
				lab.setPas("123456a");
				lac.setData(lab);
				lac.callService();
				LoginSafeConfiguration.checkLoginStatusWithBlackIp(lac, true, ip);
			} else {
				Logger.verifyEquals(0, LoginSafeConfiguration.IP_LOGIN_SUCCESS_LIMIT, "次数为0，此case无需运行");
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_LoginAuth_013() {
		Logger.start(false, "某个设备号在1分内连续进行20次的登录成功记录，提示需要身份验证");
		try {
			// 这里会在触发规则之前被其他规则拦截
			com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean urb = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer UserId = uc.getUserid();
			String AccessToken=uc.getAccessToken();
			
			String UserName = urb.getLoginMobile();
			String ip=urb.getClientIp();
			
			String loginid = urb.getLoginId();
			String deviceId = TestDataManager.getRandomUUID().toString();
			Logger.comment("用同一设备不同的用户进行正确登陆" + LoginSafeConfiguration.DEVICE_LOGIN_SUCCESS_LIMIT + "次");
			int limit = LoginSafeConfiguration.DEVICE_LOGIN_SUCCESS_LIMIT;
			Logger.comment("删除设备黑名单和历史登陆数据(如果存在)");
			checkDeviceLoginHistory(deviceId, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));

			for (int j = 0; j <= limit; j++) {
				Logger.debug("第" + j + "次登入");
					lab = new LoginAuthBean();
					lac = new LoginAuthCall();
					lab.setLoginId(UserName);
					lab.setClientIp("127.0.0.1");
					lab.setSourceType("app");
					lab.setPas("123456a");
					lab.setDeviceId(deviceId);
					lab.setClientId("aaaa12");
					lac.setData(lab);
					lac.callService();
			}
			Thread.sleep(1000);
			Logger.comment("进行第" + (LoginSafeConfiguration.DEVICE_LOGIN_SUCCESS_LIMIT + 1) + "次登陆");
			lab = new LoginAuthBean();
			lac = new LoginAuthCall();
			lab.setLoginId(UserName);
			lab.setClientIp("127.0.0.1");
			lab.setSourceType("app");
			lab.setPas("123456a");
			lab.setDeviceId(deviceId);
			lab.setClientId("aaaa12");
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals("false", lac.getString("Success"), "验证登陆失败");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_014() {
		Logger.start(false, "设备号不存在设备认证库中，提示需要身份验证");
		try {
			Logger.comment("前置条件准备");
			int userId = 438;
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			String deviceId = TestDataManager.getRandomNum(6);
			Logger.comment("如果设备已认证过，则删除此认证数据");
			authWapper.deleteDeviceData(userId, deviceId);

			Logger.comment("登陆此用户");
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp("1.1.9.1");
			lab.setSourceType("app");
			lab.setDeviceId(deviceId);
			lab.setClientId("aaaa");
			lac.setData(lab);
			lac.callService();
			if (LoginSafeConfiguration.isAppAppDeviceOpen) {
				Logger.comment("安全认证是打开状态，需要进行安全认证");
				Logger.verifyEquals("false", lac.getString("Success"), "验证登陆失败");
				Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");
				Logger.comment("验证该设备已存入认证库中");
				Thread.sleep(1000);
				Map<String, Object> authDevice = authWapper.getDeviceAuthByUserIdAndDeviceId(user.getuId(), deviceId).get(0);
				Logger.verifyEquals(0, authDevice.get("AuthStatus"), "验证认证状态");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	// case变更 现在第一次注册才是成功，登入和注册不同失败
	public void Tc_LoginAuth_015() {
		Logger.start(true, "用户第一次使用IP区域登陆验证，提示登陆成功，该用户Ip区域存入IP认证库");
		try {
			Logger.comment("前置条件准备");
			Map m = UserCallService.registerUser(TestDataManager.getEmail(), null, null);
			Logger.debug(m);
			String ip = "100.100.100.100"; // Shared address,Shared address
			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			Logger.comment("删除Ip黑名单，删除IP在一天内的历史记录");
			checkIpLoginHistory(ip, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));

			Logger.comment("登陆此用户");
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp(ip);
			lab.setSourceType("mainsite");
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals("true", lac.getString("Success"), "验证登陆成功");
			Thread.sleep(1000);
			Logger.comment("验证该IP区域已存入认证库中");
			Map<String, Object> ipAuth = authWapper.getIPAuthByUserIdAndArea(userId, null, null, null);
			Logger.verifyNotNull(ipAuth, "验证IP认证已存入数据库中");
			if (LoginSafeConfiguration.AUTH_PC_OPEN) {
				Logger.verifyEquals(200, ipAuth.get("AuthStatus"), "验证认证状态为成功");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	@Ignore
	// 90天case变更 被后面case替换
	public void Tc_LoginAuth_016() {
		Logger.start(false, "设备号最后一次token认证时间大于90天");
		try {
			Logger.comment("前置条件准备");
			ULC201406Bean user = userWapper.getULCInfoByUid(1204);
			userWapper.updatePwdByUid(1204);
			String deviceId = "tokenOld";
			String dateTime = YMTDateUtil.getBeforeOrNextDay(-100);

			Logger.comment("如果认证数据库中不存在该设备的Token记录，则插入token数据，并将token的最后更新时间更改为90天以前");
			Map<String, Object> deviceAuth = authWapper.getDeviceAuthByUserIdAndDeviceId(user.getuId(), deviceId).get(0);
			if (deviceAuth == null) {
				authWapper.insertDeviceTokenAuthHistory(user.getuId(), deviceId, 1, dateTime, dateTime);
				authWapper.insertDataToUserDeviceAuth(user.getuId(), deviceId, 200, dateTime, dateTime, "app", dateTime, 1, "");
			} else {
				authWapper.updateTokenUpdateTime(user.getuId(), deviceId, dateTime);
			}

			Logger.comment("登陆此用户");
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp("1.105.1.2");
			lab.setSourceType("app");
			lab.setDeviceId(deviceId);
			lac.setData(lab);
			lac.callService();
			if (LoginSafeConfiguration.isAppAppDeviceOpen) {
				LoginSafeConfiguration.checkLoginStatus(lac);
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	@Ignore
	public void Tc_LoginAuth_017() {
		Logger.start(false, "IP最后一次token认证时间大于90天，提示需要认证");
		try {
			String ip = "1.1.10.1";// China,Guangdong,*
			int userId = 705;
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);

			Logger.comment("如果认证数据库中不存在该IP的Token记录，则插入token数据，并将token的最后更新时间更改为90天以前");
			Map<String, Object> ipAuth = authWapper.getIPAuthByUserIdAndArea(userId, "China", "Guangdong", "*");
			String dateTime = YMTDateUtil.getBeforeOrNextDay(-100);
			if (ipAuth == null) {
				authWapper.insertIPTokenAuthHistory(userId, "China", "Guangdong", "*", dateTime, dateTime);
				authWapper.insertUserIpAuth(userId, "China", "Guangdong", "*", 200, dateTime, dateTime, "mainsite", dateTime, dateTime);
			} else {
				authWapper.updateTokenUpdateTime(userId, "China", "Guangdong", "*", dateTime);
			}

			Logger.comment("登陆此用户");
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp(ip);
			lab.setSourceType("www.ymatou.com");
			lac.setData(lab);
			lac.callService();

			LoginSafeConfiguration.checkLoginStatus(lac);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_018() {
		Logger.start(false, "App端，使用上次认证失败过的设备登陆,提示需要认证");
		try {
			ULC201406Bean user = userWapper.getULCInfoByUid(572);
			String deviceId = "Authfailed";
			String dateTime = YMTDateUtil.getBeforeOrNextDay(-1);
			Logger.comment("如果认证数据库中不存在该设备的认证记录，则插入此数据，否则更改此认证状态为失败状态(-200)");
			Map<String, Object> deviceAuth = authWapper.getDeviceAuthByUserIdAndDeviceId(user.getuId(), deviceId).get(0);
			if (deviceAuth == null) {
				authWapper.insertDataToUserDeviceAuth(user.getuId(), deviceId, -200, dateTime, dateTime, "app", dateTime, 1, "");
			} else if (deviceAuth.get("AuthStatus").toString() != "200") {
				authWapper.updateAuthStatus(user.getuId(), deviceId, -200);
			}

			Logger.comment("登陆此用户");
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp("1.100.1.2");
			lab.setSourceType("app");
			lab.setDeviceId(deviceId);
			lac.setData(lab);
			lac.callService();
			if (LoginSafeConfiguration.isAppAppDeviceOpen) {
				LoginSafeConfiguration.checkLoginStatus(lac);
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_LoginAuth_019() {
		Logger.start(false, "PC端，使用上次认证失败过的IP登陆");
		try {
			String ip = "1.11.10.1";
			ULC201406Bean user = userWapper.getULCInfoByUid(571);

			Logger.comment("如果认证数据库中不存在该Ip的认证记录，则插入此数据，否则更改此认证状态为失败状态(-200)");
			Map<String, Object> ipAuth = authWapper.getIPAuthByUserIdAndArea(user.getuId(), "The Republic of Korea", "The Republic of Korea", "*");
			String dateTime = YMTDateUtil.getBeforeOrNextDay(-10);
			if (ipAuth == null) {
				authWapper.insertUserIpAuth(user.getuId(), "The Republic of Korea", "The Republic of Korea", "*", -200, dateTime, dateTime, "mainsite", dateTime, dateTime);
			} else {
				authWapper.updateAuthStatus(user.getuId(), "The Republic of Korea", "The Republic of Korea", "*", -200);
			}

			Logger.comment("登陆此用户");
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp(ip);
			lab.setSourceType("mainsite");
			lac.setData(lab);
			lac.callService();

			LoginSafeConfiguration.checkLoginStatus(lac);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_LoginAuth_020() {
		Logger.start(false, "通过PC，1分钟内登陆失败20次，ip进入黑名单");
		try {
			if (LoginSafeConfiguration.IP_LOGIN_FAIL_LIMIT > 0) {
				authWapper = new UserSafeWapper();
				List<Map<String, Object>> authIPArea = authWapper.getIPAuthData(200, YMTDateUtil.getBeforeOrNextDay(-90), "United States", "America");
				if (authIPArea == null) {
					Assert.fail("没有测试数据");
				}
				String ip = "11.100.100.100";
				checkIpLoginHistory(ip, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));

				Logger.comment("用同一IP不同的用户进行错误密码登陆" + LoginSafeConfiguration.IP_LOGIN_FAIL_LIMIT + "次");
				int limit = LoginSafeConfiguration.IP_LOGIN_FAIL_LIMIT;
				for (int j = 0; j <= limit; j++) {
					ULC201406Bean user = userWapper.getULCInfoByUid((Integer) authIPArea.get(j).get("UserId"));
					if (user != null) {
						lab = new LoginAuthBean();
						lac = new LoginAuthCall();
						lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
						lab.setClientIp(ip);
						lab.setSourceType("www.ymatou.com");
						lab.setPas("456789");
						lac.setData(lab);
						lac.callService();
						Logger.verifyEquals("false", lac.getString("Success"), "验证登陆失败");
					} else {
						++limit;
					}
				}

				Logger.comment("进行第" + (LoginSafeConfiguration.IP_LOGIN_FAIL_LIMIT + 1) + "次登陆");
				int userId = (Integer) authIPArea.get(10).get("UserId");
				ULC201406Bean user = userWapper.getULCInfoByUid(userId);
				userWapper.updatePwdByUid(userId);
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
				lab.setClientIp(ip);
				lab.setSourceType("www.ymatou.com");
				lab.setPas("123456a");
				lac.setData(lab);
				lac.callService();
				LoginSafeConfiguration.checkLoginStatusWithBlackIp(lac, true, ip);
			} else {
				Logger.verifyEquals(0, LoginSafeConfiguration.IP_LOGIN_FAIL_LIMIT, "次数为0，无需运行此case");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_LoginAuth_021() {
		Logger.start(false, "某个设备号在1分内连续进行20次的登录失败记录，提示需要身份验证");
		try {
			List<Map<String, Object>> authDevice = authWapper.getDeviceAuthData(200, YMTDateUtil.getBeforeOrNextDay(-90), "BlackDevice");
			if (authDevice == null) {
				throw new Exception("没有测试数据");
			}
			String deviceId = "BlackDevice";
			checkDeviceLoginHistory(deviceId, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));

			Logger.comment("用同一设备不同的用户进行错误密码登陆" + LoginSafeConfiguration.DEVICE_LOGIN_FAIL_LIMIT + "次");
			for (int j = 0; j < LoginSafeConfiguration.DEVICE_LOGIN_FAIL_LIMIT; j++) {
				ULC201406Bean user = userWapper.getULCInfoByUid((Integer) authDevice.get(j).get("UserId"));
				if (user != null) {
					lab = new LoginAuthBean();
					lac = new LoginAuthCall();
					lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
					lab.setClientIp("1.115.1.1");
					lab.setSourceType("app");
					lab.setPas("123789");
					lab.setDeviceId(deviceId);
					lab.setClientId(deviceId);
					lac.setData(lab);
					lac.callService();
					Logger.verifyEquals("false", lac.getString("Success"), "验证登陆失败");
				}
			}

			Thread.sleep(1000);
			Logger.comment("进行第" + (LoginSafeConfiguration.DEVICE_LOGIN_FAIL_LIMIT + 1) + "次登陆");
			int userId = (Integer) authDevice.get(4).get("UserId");
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			lab = new LoginAuthBean();
			lac = new LoginAuthCall();
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setClientIp("1.115.1.1");
			lab.setSourceType("app");
			lab.setPas("123456a");
			lab.setDeviceId(deviceId);
			lab.setClientId(deviceId);
			lac.setData(lab);
			lac.callService();
			LoginSafeConfiguration.checkLoginStatusWithBlackIp(lac, true, deviceId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_LoginAuth_022() {
		Logger.start(true, "Pc端，使用IP区域库中不存在的IP进行登陆，登陆成功");
		try {
			Map<String, Object> authIPArea = authWapper.getIPAuth(200, YMTDateUtil.getBeforeOrNextDay(-90), "China", "Fujian");
			if (authIPArea == null) {
				throw new Exception("没有测试数据");
			}
			String ip = "266.1.3.1";
			int userId = (Integer) authIPArea.get("UserId");
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);

			Logger.comment("登陆此用户");
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp(ip);
			lab.setSourceType("Mainsite");
			lab.setClientId(TestDataManager.getRandomUUID().toString());
			lac.setData(lab);
			lac.callService();

			Logger.verifyEquals("true", lac.getString("Success"), "验证登陆成功");
			Logger.verifyEquals(userId, lac.getUserData().getUserId(), "验证用户ID");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_LoginAuth_023() {
		Logger.start(true, "未输入设备号，clientID不存在设备认证库中，验证登入");
		try {
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip="1.1.9.1";
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			String clientId = "NotExistInDB";
			authWapper.deleteDeviceData(UserId, clientId);

			Logger.comment("登陆此用户");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setClientIp(ip);
			lab.setSourceType("app");
			lab.setClientId(clientId);
			lac.setData(lab);
			lac.callService();
			int appClientStatus = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppClientId", "ExistsCheck").get("Value").toString());
			int appDeviceStatus = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppDevice", "ExistsCheck").get("Value").toString());
			int authFailActionStatus = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppClientId", "AuthFailAction").get("Value").toString());
			
			Logger.debug(appDeviceStatus);
			if ((appClientStatus==1&&authFailActionStatus==100)||appDeviceStatus == 1) {
				Logger.verifyEquals("false", lac.getString("Success"), "验证登陆成功");
				Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");
			} else {
				Logger.verifyEquals("true", lac.getString("Success"), "验证登陆成功");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_LoginAuth_024() {
		Logger.start(false, "用户在其他IP区域认证过，再次使用未认证过的Ip区域登陆，即该Ip区域不存入IP认证库，提示需要认证");
		try {
			String ip = "100.100.100.100"; // Shared address,Shared address
			String email = TestDataManager.getEmail();
			String phone = TestDataManager.getPhoneNum();
			Map m = UserCallService.registerUser(email, phone, ip);
			Logger.debug(m);

			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			checkIpLoginHistory(ip, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			Logger.comment("登陆此用户");
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp(ip);
			lab.setSourceType("mainsite");
			lac.setData(lab);
			lac.callService();
			Thread.sleep(1000);
			Map<String, Object> ipAuth = authWapper.getIPAuthByUserIdAndArea(userId, "Shared address", "Shared address", "*");
			Logger.verifyNotNull(ipAuth, "验证IP认证已存入数据库中");
			Logger.verifyEquals(200, ipAuth.get("AuthStatus"), "验证认证状态为成功");
			Thread.sleep(2000);
			String newIp = "059.077.172.002";// fujian
			lab.setClientIp(newIp);
			lac = new LoginAuthCall();
			lac.setData(lab);
			lac.callService();
			LoginSafeConfiguration.checkLoginStatus(lac);
			Thread.sleep(1000);
			Map<String, Object> ipAuth1 = authWapper.getIPAuthByUserIdAndArea(userId, "China", "Fujian", null);
			Logger.verifyNotNull(ipAuth1, "验证IP认证已存入数据库中");
			if (LoginSafeConfiguration.AUTH_PC_OPEN) {
				Logger.verifyEquals(200, ipAuth.get("AuthStatus"), "验证认证状态为成功");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_025() {
		Logger.start(true, "注册用户第一次在app上登陆，登入认证成功");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip=TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			Thread.sleep(5000);
			HashMap m = new HashMap();
			m.put("Uid", UserId);
			List<Map> list = new LoginHistoryWapper().selectUserRegHistoryByUid(m);
			Logger.verifyEquals(1, list.size(), "验证UserRegHistory表记录");

			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setClientId("test_" + TestDataManager.getRandomNum(10));
			lab.setClientIp(ip);
			lab.setPas("123456a");
			lab.setSourceType("app");
			lac.setData(lab);
			lac.callService();
			//新ClientId且用户第一次认证如果开启AutoAuthSuccess自动成功 否则需要认证
			int status = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppUserFirstLogin", "AutoAuthSuccess").get("Value").toString());
			if (status == 1) {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyEquals(phone, lac.getUserData().getLoginMobile(), "验证UserName");
				Logger.verifyNotNull(AccessToken, "验证AccessToken");
				Logger.verifyEquals(UserId, lac.getUserData().getUserId(), "验证UserId");
				Logger.verifyEquals(email.toLowerCase(), lac.getUserData().getLoginMail().toLowerCase(), "验证登录邮箱");
				Map<String, Object> info = authWapper.getIPAuthByUserIdAndArea(UserId, null, null, null);
				Logger.verifyEquals(String.valueOf(UserId), info.get("UserId").toString(), "验证UserId信息");
			} else {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_026() {
		Logger.start(true, "注册用户第一次在APP端登陆，登入认证成功");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();

			// 成都
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			String did = (String) UserMap.get("did");
			Thread.sleep(5000);
			HashMap m = new HashMap();
			m.put("Uid", UserId);
			List<Map> list = new LoginHistoryWapper().selectUserRegHistoryByUid(m);
			Logger.verifyEquals(1, list.size(), "验证UserRegHistory表记录");

			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("app");
			lab.setClientIp(ip);
			lab.setDeviceId(did);
			lac.setData(lab);
			lab.setClientIp(ip);
			lac.callService();
			int status = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppUserFirstLogin", "AutoAuthSuccess").get("Value").toString());
			int appstatus = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppDevice", "StatusCheck").get("Value").toString());
			if (status == 1) {
				if(appstatus==1){
					Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				}else{
					Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
				}
				Logger.verifyEquals(phone, lac.getUserData().getLoginMobile(), "验证UserName");
				Logger.verifyNotNull(AccessToken, "验证AccessToken");
				Logger.verifyEquals(UserId, lac.getUserData().getUserId(), "验证UserId");
				Logger.verifyEquals(email.toLowerCase(), lac.getUserData().getLoginMail().toLowerCase(), "验证登录邮箱");
				Map<String, Object> info = authWapper.getIPAuthByUserIdAndArea(UserId, null, null, null);
				Logger.verifyEquals(String.valueOf(UserId), info.get("UserId").toString(), "验证UserId信息");
			} else {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_027() {
		Logger.start(true, "app用户换IP区域登入,风控");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			// 成都
			Map UserMap = UserCallService.registerUser(email, phone, "223.87.236.54");
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			Thread.sleep(5000);
			HashMap m = new HashMap();
			m.put("Uid", UserId);
			List<Map> list = new LoginHistoryWapper().selectUserRegHistoryByUid(m);
			Logger.verifyEquals(1, list.size(), "验证UserRegHistory表记录");

			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("app");
			lab.setDeviceId(TestDataManager.getRandomUUID().toString());
			// 无锡
			lab.setClientIp("223.110.4.1");
			lac.setData(lab);
			lac.callService();
			if (LoginSafeConfiguration.AUTH_PC_OPEN && LoginSafeConfiguration.isAppAppDeviceOpen) {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	@Ignore
	public void Tc_LoginAuth_028() {
		Logger.start(false, "app最后一次token认证时间大于90天");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();
			// 成都
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			Map m = AuthCallService.authLogin(UserName, "123456a", "app", ip);
			AuthCallService.signAuth(m.get("accessToken").toString(), ip);
			Thread.sleep(1000);
			String deviceId = "tokenOld";
			String dateTime = YMTDateUtil.getBeforeOrNextDay(-100);
			authWapper = new UserSafeWapper();
			authWapper.updateTokenUpdateTime(UserId, null, null, null, dateTime);
			Thread.sleep(1000);
			Logger.comment("登陆此用户");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setClientIp(ip);
			lab.setSourceType("app");
			lab.setDeviceId(deviceId);
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_029() {
		Logger.start(true, "注册后连续登入2次app,使用相同设备号，登入认证成功");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			Map UserMap = UserCallService.registerUser(email, phone, null);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			Thread.sleep(5000);
			HashMap m = new HashMap();
			m.put("Uid", UserId);
			List<Map> list = new LoginHistoryWapper().selectUserRegHistoryByUid(m);
			Logger.verifyEquals(1, list.size(), "验证UserRegHistory表记录");
			String deviceId = TestDataManager.getRandomUUID().toString();
			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("app");
			lab.setDeviceId(deviceId);
			lac.setData(lab);
			lab.setClientIp("120.1.1.1");
			lac.callService();
			lac.callService();
			int status = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppUserFirstLogin", "AutoAuthSuccess").get("Value").toString());
			if (status == 1) {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyEquals(phone, lac.getUserData().getLoginMobile(), "验证UserName");
				Logger.verifyEquals(UserId, lac.getUserData().getUserId(), "验证UserId");
				Logger.verifyEquals(email.toLowerCase(), lac.getUserData().getLoginMail().toLowerCase(), "验证登录邮箱");
				Map<String, Object> info = authWapper.getIPAuthByUserIdAndArea(UserId, null, null, null);
				Map<String, Object> info2 = authWapper.getDeviceAuthByUserIdAndDeviceId(UserId, deviceId).get(0);
				Logger.verifyEquals(String.valueOf(UserId), info.get("UserId").toString(), "验证UserId信息");
				if (LoginSafeConfiguration.isAppAppDeviceOpen) {
					Logger.verifyEquals(false, info2.get("Type"), "验证Type信息");
					Logger.verifyEquals(String.valueOf(UserId), info.get("UserId").toString(), "验证UserId信息");
					Logger.verifyEquals(deviceId, info2.get("DeviceId").toString(), "验证DeviceId信息");
					Logger.verifyEquals("app", info.get("AppSource").toString(), "验证AppSource信息");
					Logger.verifyEquals("0", info.get("AuthStatus").toString(), "验证AuthStatus信息");
				}
			} else {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_030() {
		Logger.start(true, "注册后连续登入2次app,使用相同clientid，登入认证成功");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			Map UserMap = UserCallService.registerUser(email, phone, null);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			Thread.sleep(5000);
			HashMap m = new HashMap();
			m.put("Uid", UserId);
			List<Map> list = new LoginHistoryWapper().selectUserRegHistoryByUid(m);
			Logger.verifyEquals(1, list.size(), "验证UserRegHistory表记录");
			String clientid = TestDataManager.getRandomUUID().toString();
			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("app");
			lab.setClientId(clientid);
			lac.setData(lab);
			lab.setClientIp("120.1.1.1");
			lac.callService();
			lac.callService();
			int status = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppUserFirstLogin", "AutoAuthSuccess").get("Value").toString());
			if (status == 1) {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyEquals(phone, lac.getUserData().getLoginMobile(), "验证UserName");
				Logger.verifyEquals(UserId, lac.getUserData().getUserId(), "验证UserId");
				Logger.verifyEquals(email.toLowerCase(), lac.getUserData().getLoginMail().toLowerCase(), "验证登录邮箱");
				Map<String, Object> info = authWapper.getIPAuthByUserIdAndArea(UserId, null, null, null);
				Logger.verifyEquals(String.valueOf(UserId), info.get("UserId").toString(), "验证UserId信息");
			} else {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_031() {
		Logger.start(true, "PC登入单用户短时间多次登入成功");
		try {
			String ip = TestDataManager.getRandomIp();
			String email = TestDataManager.getEmail();
			String phone = TestDataManager.getPhoneNum();
			Map m = UserCallService.registerUser(email, phone, ip);
			Logger.debug(m);

			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			checkIpLoginHistory(ip, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			Logger.comment("循环登陆此用户");
			for (int i = 0; i < 9; i++) {
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
				lab.setPas("123456a");
				lab.setClientIp(ip);
				lab.setSourceType("Mainsite");
				lac.setData(lab);
				lac.callService();
			}
			if (!lac.getSuccess()) {
				if (lac.getString("LastErrorMessage") != null && lac.getString("LastErrorMessage").equals("登录频繁请休息会")) {
					throw new Exception("未跑到风控认证,登入次数限制拦截");
				}
			} else {
				Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
				Logger.verifyEquals(phone, lac.getUserData().getLoginMobile(), "验证UserName");
				Logger.verifyEquals(email.toLowerCase(), lac.getUserData().getLoginMail().toLowerCase(), "验证登录邮箱");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_032() {
		Logger.start(false, "PC登入单用户短时间多次密码错误登入失败,风控认证");
		try {
			String ip = TestDataManager.getRandomIp();
			String email = TestDataManager.getEmail();
			String phone = TestDataManager.getPhoneNum();
			Map m = UserCallService.registerUser(email, phone, ip);
			Logger.debug(m);

			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			checkIpLoginHistory(ip, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			Logger.comment("循环登陆此用户");
			for (int i = 0; i < 9; i++) {
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
				lab.setPas("1234561");
				lab.setClientIp(ip);
				lab.setSourceType("Mainsite");
				lac.setData(lab);
				lac.callService();
			}
			if (!lac.getSuccess()) {
				if (lac.getString("LastErrorMessage") != null && lac.getString("LastErrorMessage").equals("登录频繁请休息会")) {
					throw new Exception("未跑到风控认证,登入次数限制拦截");
				}
			} else {
				Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
				Logger.verifyEquals(phone, lac.getUserData().getLoginMobile(), "验证UserName");
				Logger.verifyEquals(email.toLowerCase(), lac.getUserData().getLoginMail().toLowerCase(), "验证登录邮箱");
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_033() {
		Logger.start(false, "PC登入同IP多用户多次登入成功用户数超限,黑名单风控认证");
		try {
			List<Map> maps = new ArrayList<>();
			String ip = TestDataManager.getRandomIp();
			for (int i = 0; i < 11; i++) {
				String email = TestDataManager.getEmail();
				String phone = TestDataManager.getPhoneNum();
				Map m = UserCallService.registerUser(email, phone, ip);
				maps.add(m);
			}
			for (Map m : maps) {
				int userId = Integer.valueOf(m.get("userId").toString());
				ULC201406Bean user = userWapper.getULCInfoByUid(userId);
				userWapper.updatePwdByUid(userId);
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
				lab.setPas("123456a");
				lab.setClientIp(ip);
				lab.setSourceType("Mainsite");
				lac.setData(lab);
				lac.callService();
			}
			String email = TestDataManager.getEmail();
			String phone = TestDataManager.getPhoneNum();
			Map m = UserCallService.registerUser(email, phone, null);

			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			lab = new LoginAuthBean();
			lac = new LoginAuthCall();
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp(ip);
			lab.setSourceType("Mainsite");
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			int status = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "PcBlacklist", "BlacklistAction").get("Value").toString());
			if (status == 100)
				Logger.verifyEquals(ECode.AUTH_E100, lac.getString("LastErrorMessage"), "验证Success");
			else if (status == 400)
				Logger.verifyEquals("登录频繁请休息会", lac.getString("LastErrorMessage"), "验证Success");
			// ymatouusersafe.loginipcountinfo
			// LoginSuccess: 登录是否成功; 0, 1
			// LoginCount: 分别计数
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_034() {
		Logger.start(false, "PC登入同IP多用户多次登入失败用户数超限,黑名单风控认证");
		try {
			List<Map> maps = new ArrayList<>();
			String ip = TestDataManager.getRandomIp();
			for (int i = 0; i < 11; i++) {
				String email = TestDataManager.getEmail();
				String phone = TestDataManager.getPhoneNum();
				Map m = UserCallService.registerUser(email, phone, ip);
				maps.add(m);
			}
			for (Map m : maps) {
				int userId = Integer.valueOf(m.get("userId").toString());
				ULC201406Bean user = userWapper.getULCInfoByUid(userId);
				userWapper.updatePwdByUid(userId);
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
				lab.setPas("1234561");
				lab.setClientIp(ip);
				lab.setSourceType("Mainsite");
				lac.setData(lab);
				lac.callService();
			}
			String email = TestDataManager.getEmail();
			String phone = TestDataManager.getPhoneNum();
			Map m = UserCallService.registerUser(email, phone, null);

			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			lab = new LoginAuthBean();
			lac = new LoginAuthCall();
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp(ip);
			lab.setSourceType("Mainsite");
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");

			Logger.comment("开始认证");
			AuthCallService.ipAreaAuthStatus(phone, ip, "Mainsite");
			lab = new LoginAuthBean();
			lac = new LoginAuthCall();
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp(ip);
			lab.setSourceType("Mainsite");
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			int status = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "PcBlacklist", "BlacklistAction").get("Value").toString());
			if (status == 100)
				Logger.verifyEquals(ECode.AUTH_E100, lac.getString("LastErrorMessage"), "验证Success");
			else if (status == 400)
				Logger.verifyEquals("登录频繁请休息会", lac.getString("LastErrorMessage"), "验证Success");
			// ymatouusersafe.loginipcountinfo
			// LoginSuccess: 登录是否成功; 0, 1
			// LoginCount: 分别计数
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_035() {
		Logger.start(false, "PC登入IP不是常用IP,风控认证(登入和注册IP不一致)");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			Thread.sleep(5000);
			HashMap m = new HashMap();
			m.put("Uid", UserId);
			List<Map> list = new LoginHistoryWapper().selectUserRegHistoryByUid(m);
			Logger.verifyEquals(1, list.size(), "验证UserRegHistory表记录");

			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("MainSite");
			lab.setClientIp("100.100.100.100");
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_036() {
		Logger.start(false, "PC登入IP未认证,风控认证(登入和注册IP不一致后再次登入IP登入)");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			Thread.sleep(5000);
			HashMap m = new HashMap();
			m.put("Uid", UserId);
			List<Map> list = new LoginHistoryWapper().selectUserRegHistoryByUid(m);
			Logger.verifyEquals(1, list.size(), "验证UserRegHistory表记录");

			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("MainSite");
			lab.setClientIp("100.100.100.100");
			lac.setData(lab);
			lac.callService();
			Logger.comment("开始登陆认证");
			lac = new LoginAuthCall();
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_037() {
		Logger.start(false, "PC登入IP认证超过90天,风控认证");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int userId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");

			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("MainSite");
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();

			String dateTime = YMTDateUtil.getBeforeOrNextDay(-100);
			UserSafeWapper authWapper = new UserSafeWapper();
			Logger.comment("更新token时间");
			authWapper.updateTokenUpdateTime(userId, null, null, null, dateTime);

			Thread.sleep(3000);

			Logger.comment("开始登陆认证");
			lac = new LoginAuthCall();
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("MainSite");
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_038() {
		Logger.start(true, "APP登入单用户短时间多次登入成功");
		try {
			String ip = TestDataManager.getRandomIp();
			String email = TestDataManager.getEmail();
			String phone = TestDataManager.getPhoneNum();
			Map m = UserCallService.registerUser(email, phone, ip);
			Logger.debug(m);

			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			checkIpLoginHistory(ip, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			Logger.comment("循环登陆此用户");
			for (int i = 0; i < 9; i++) {
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
				lab.setPas("123456a");
				lab.setClientIp(ip);
				lab.setSourceType("app");
				lac.setData(lab);
				lac.callService();
			}
			if (!lac.getSuccess()) {
				if (lac.getString("LastErrorMessage") != null && lac.getString("LastErrorMessage").equals("登录频繁请休息会")) {
					throw new Exception("未跑到风控认证,登入次数限制拦截");
				}
			} else {
				Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
				Logger.verifyEquals(phone, lac.getUserData().getLoginMobile(), "验证UserName");
				Logger.verifyEquals(email.toLowerCase(), lac.getUserData().getLoginMail().toLowerCase(), "验证登录邮箱");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_039() {
		Logger.start(false, "APP登入单用户短时间多次密码错误登入失败,黑名单风控认证");
		try {
			String ip = TestDataManager.getRandomIp();
			String email = TestDataManager.getEmail();
			String phone = TestDataManager.getPhoneNum();
			Map m = UserCallService.registerUser(email, phone, ip);
			Logger.debug(m);

			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			checkIpLoginHistory(ip, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			Logger.comment("循环登陆此用户");
			for (int i = 0; i < 9; i++) {
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
				lab.setPas("1234561");
				lab.setClientIp(ip);
				lab.setSourceType("app");
				lac.setData(lab);
				lac.callService();
			}
			if (!lac.getSuccess()) {
				if (lac.getString("LastErrorMessage") != null && lac.getString("LastErrorMessage").equals("登录频繁请休息会")) {
					throw new Exception("未跑到风控认证,登入次数限制拦截");
				}
			} else {
				Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
				Logger.verifyEquals(phone, lac.getUserData().getLoginMobile(), "验证UserName");
				Logger.verifyEquals(email.toLowerCase(), lac.getUserData().getLoginMail().toLowerCase(), "验证登录邮箱");
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_040() {
		Logger.start(false, "APP登入同IP多用户多次登入成功用户数超限,黑名单风控认证");
		try {
			List<Map> maps = new ArrayList<>();
			String ip = TestDataManager.getRandomIp();
			for (int i = 0; i < 11; i++) {
				String email = TestDataManager.getEmail();
				String phone = TestDataManager.getPhoneNum();
				Map m = UserCallService.registerUser(email, phone, ip);
				maps.add(m);
			}
			for (Map m : maps) {
				int userId = Integer.valueOf(m.get("userId").toString());
				ULC201406Bean user = userWapper.getULCInfoByUid(userId);
				userWapper.updatePwdByUid(userId);
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
				lab.setPas("123456a");
				String deviceId = TestDataManager.getRandomUUID().toString();
				lab.setDeviceId(deviceId);
				lab.setClientIp(ip);
				lab.setSourceType("Mainsite");
				lac.setData(lab);
				lac.callService();
			}
			String email = TestDataManager.getEmail();
			String phone = TestDataManager.getPhoneNum();
			Map m = UserCallService.registerUser(email, phone, null);

			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			lab = new LoginAuthBean();
			lac = new LoginAuthCall();
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			String deviceId = TestDataManager.getRandomUUID().toString();
			lab.setDeviceId(deviceId);
			lab.setClientIp(ip);
			lab.setSourceType("app");
			lac.setData(lab);
			lac.callService();
			int checkapp = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppIpBlacklist", "Check").get("Value").toString());
			if (checkapp == 1) {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				int status = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppIpBlacklist", "BlacklistAction").get("Value").toString());
				if (status == 100)
					Logger.verifyEquals(ECode.AUTH_E100, lac.getString("LastErrorMessage"), "验证Success");
				else if (status == 400)
					Logger.verifyEquals("登录频繁请休息会", lac.getString("LastErrorMessage"), "验证Success");
			} else {
				Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_041() {
		Logger.start(false, "APP登入同IP多用户多次登入失败用户数超限,黑名单风控认证");
		try {
			List<Map> maps = new ArrayList<>();
			String ip = TestDataManager.getRandomIp();
			for (int i = 0; i <= 11; i++) {
				String email = TestDataManager.getEmail();
				String phone = TestDataManager.getPhoneNum();
				Map m = UserCallService.registerUser(email, phone, ip);
				maps.add(m);
			}
			for (Map m : maps) {
				int userId = Integer.valueOf(m.get("userId").toString());
				ULC201406Bean user = userWapper.getULCInfoByUid(userId);
				userWapper.updatePwdByUid(userId);
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
				lab.setPas("123456a");
				String deviceId = TestDataManager.getRandomUUID().toString();
				lab.setDeviceId(deviceId);
				lab.setClientIp(ip);
				lab.setSourceType("Mainsite");
				lac.setData(lab);
				lac.callService();
			}
			String email = TestDataManager.getEmail();
			String phone = TestDataManager.getPhoneNum();
			Map m = UserCallService.registerUser(email, phone, null);

			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			lab = new LoginAuthBean();
			lac = new LoginAuthCall();
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("1234561");
			String deviceId = TestDataManager.getRandomUUID().toString();
			lab.setDeviceId(deviceId);
			lab.setClientIp(ip);
			lab.setSourceType("app");
			lac.setData(lab);
			lac.callService();
			int checkapp = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppIpBlacklist", "Check").get("Value").toString());
			if (checkapp == 1) {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				int status = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppIpBlacklist", "BlacklistAction").get("Value").toString());
				if (status == 100)
					// 20160726-修改风控规则 先做密码判断
					Logger.verifyIsContains("密码错误", lac.getString("LastErrorMessage"), "验证LastErrorMessage");
				else if (status == 400)
					Logger.verifyEquals("登录频繁请休息会", lac.getString("LastErrorMessage"), "验证Success");
			} else {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyIsContains("密码错误", lac.getString("LastErrorMessage"), "验证LastErrorMessage");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_042() {
		Logger.start(false, "APP登入IP不是常用IP,风控认证(登入和注册IP不一致)");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			Thread.sleep(5000);
			HashMap m = new HashMap();
			m.put("Uid", UserId);
			List<Map> list = new LoginHistoryWapper().selectUserRegHistoryByUid(m);
			Logger.verifyEquals(1, list.size(), "验证UserRegHistory表记录");

			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("app");
			lab.setClientIp("100.100.100.100");
			String deviceId=TestDataManager.getRandomUUID().toString();
			lab.setDeviceId(deviceId);
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_043() {
		Logger.start(false, "APP登入IP未认证,风控认证(登入和注册IP不一致后再次登入IP登入)");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			Thread.sleep(5000);
			HashMap m = new HashMap();
			m.put("Uid", UserId);
			List<Map> list = new LoginHistoryWapper().selectUserRegHistoryByUid(m);
			Logger.verifyEquals(1, list.size(), "验证UserRegHistory表记录");

			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("MainSite");
			lab.setClientIp("100.100.100.100");
			lac.setData(lab);
			lac.callService();
			Logger.comment("开始登陆认证");
			lac = new LoginAuthCall();
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_044() {
		Logger.start(false, "APP登入IP认证超过90天,风控认证");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int userId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			Thread.sleep(5000);

			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("MainSite");
			lab.setClientIp(ip);
			String deviceId=TestDataManager.getRandomUUID().toString();
			lab.setDeviceId(deviceId);
			lac.setData(lab);
			lac.callService();

			String dateTime = YMTDateUtil.getBeforeOrNextDay(-100);
			UserSafeWapper authWapper = new UserSafeWapper();
			Logger.comment("更新token时间");
			authWapper.updateTokenUpdateTime(userId, null, null, null, dateTime);
			Thread.sleep(3000);
			Logger.comment("开始登陆认证");
			lac = new LoginAuthCall();
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("app");
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_045() {
		Logger.start(false, "同一设备号APP登入单用户短时间多次成功登入,根据DeviceLoginSuccessLimit判断超过风控规则失败");
		try {
			//设备号开关关闭时不生效
			String ip = TestDataManager.getRandomIp();
			String email = TestDataManager.getEmail();
			String phone = TestDataManager.getPhoneNum();
			Map m = UserCallService.registerUser(email, phone, ip);
			Logger.debug(m);
			int limit = Integer.valueOf(authWapper.getLoginSafeConfiguration("BlackList", "Device", "DeviceLoginSuccessLimit").get("Value").toString());
			int limitopen = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppIpBlacklist", "Check").get("Value").toString());
			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			checkIpLoginHistory(ip, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			String deviceId = TestDataManager.getRandomUUID().toString();
			Logger.comment("循环登陆此用户");
			for (int i = 0; i <= limit + 1; i++) {
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
				lab.setPas("123456a");
				lab.setDeviceId(deviceId);
				lab.setClientIp(ip);
				lab.setSourceType("app");
				lac.setData(lab);
				lac.callService();
			}
			if (limitopen == 1) {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");
			} else {
				Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LoginAuth_046() {
		Logger.start(false, "同一设备号APP登入单用户短时间多次登入密码错误,根据DeviceLoginFailLimit判断超过风控规则失败");
		try {
			String ip = TestDataManager.getRandomIp();
			String email = TestDataManager.getEmail();
			String phone = TestDataManager.getPhoneNum();
			Map m = UserCallService.registerUser(email, phone, ip);
			Logger.debug(m);
			int limit = Integer.valueOf(authWapper.getLoginSafeConfiguration("BlackList", "Device", "DeviceLoginFailLimit").get("Value").toString());
			int userId = Integer.valueOf(m.get("userId").toString());
			ULC201406Bean user = userWapper.getULCInfoByUid(userId);
			userWapper.updatePwdByUid(userId);
			checkIpLoginHistory(ip, YMTDateUtil.getDateForMongoFormat(-1, 0, 0));
			String deviceId = TestDataManager.getRandomUUID().toString();
			Logger.comment("循环登陆此用户");
			for (int i = 0; i <= limit + 1; i++) {
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
				lab.setPas("1234561");
				lab.setDeviceId(deviceId);
				lab.setClientIp(ip);
				lab.setSourceType("app");
				lac.setData(lab);
				lac.callService();
			}
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			if(lac.getString("ErrorCode").equals("-410")){
				Logger.verifyIsContains("您登陆过于频繁", lac.getString("LastErrorMessage"), "验证LastErrorMessage");
			}else{
				Logger.verifyIsContains("密码错误", lac.getString("LastErrorMessage"), "验证LastErrorMessage");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
//	@Ignore
	public void Tc_LoginAuth_047() {
		Logger.start(false, "PC首次登入,注册不带ip第一次登入认证,根据PcUserFirstLogin判断是否风控");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, null);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			//
			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("mainsite");
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();
			int status = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "PcUserFirstLogin", "AutoAuthSuccess").get("Value").toString());
			if (status == 1)
				Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			else if (status == 0) {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyEquals(ECode.AUTH_E100, lac.getString("LastErrorMessage"), "验证Success");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_048() {
		Logger.start(false, "app首次登入,注册不带ip第一次登入认证,根据AppUserFirstLogin判断是否风控");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, null);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("app");
			String deviceId = TestDataManager.getRandomUUID().toString();
			lab.setDeviceId(deviceId);
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();
			int status = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppUserFirstLogin", "AutoAuthSuccess").get("Value").toString());
			if (status == 1)
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			else if (status == 0) {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyEquals(ECode.AUTH_E100, lac.getString("LastErrorMessage"), "验证Success");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_049() {
		Logger.start(true, "注册用户第一次在app端登陆，登入认证成功");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			//
			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("app");
			String deviceId = TestDataManager.getRandomUUID().toString();
			lab.setDeviceId(deviceId);
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();
			int status = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppUserFirstLogin", "AutoAuthSuccess").get("Value").toString());
			int appstatus = Integer.valueOf(authWapper.getLoginSafeConfiguration("LoginSafe", "AppDevice", "StatusCheck").get("Value").toString());
			if (status == 1) {
				if(appstatus==1){
					Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				}else{
					Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
				}
				Logger.verifyEquals(phone, lac.getUserData().getLoginMobile(), "验证UserName");
				Logger.verifyNotNull(AccessToken, "验证AccessToken");
				Logger.verifyEquals(UserId, lac.getUserData().getUserId(), "验证UserId");
				Logger.verifyEquals(email.toLowerCase(), lac.getUserData().getLoginMail().toLowerCase(), "验证登录邮箱");
				Map<String, Object> info = authWapper.getIPAuthByUserIdAndArea(UserId, null, null, null);
				Logger.verifyEquals(String.valueOf(UserId), info.get("UserId").toString(), "验证UserId信息");
			} else {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_050() {
		Logger.start(true, "登入loginid长度超过20的用户认证成功");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = "autotest_" + TestDataManager.getRandomNumToHex(20);
			UserCallService.modifyLoginId(UserId, UserName);
			//
			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("mainsite");
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(phone, lac.getUserData().getLoginMobile(), "验证UserName");
			Logger.verifyNotNull(AccessToken, "验证AccessToken");
			Logger.verifyEquals(UserId, lac.getUserData().getUserId(), "验证UserId");
			Logger.verifyEquals(UserName.toLowerCase(), lac.getUserData().getLoginId().toLowerCase(), "验证登陆ID");
			Logger.verifyEquals(email.toLowerCase(), lac.getUserData().getLoginMail().toLowerCase(), "验证登录邮箱");
			Logger.verifyEquals(AccessToken, lac.getUserData().getSign(), "验证Token信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	@Ignore
	public void Tc_LoginAuth_051() {
		Logger.start(false, "seller账号多次同ip登入,ip加入黑名单");
		try {
			String ip = TestDataManager.getRandomIp();
			int userid = 92;
			int success = 1;
			int failed = 1;
			int slimit = Integer.valueOf(authWapper.getLoginSafeConfiguration("BlackList", "Ip", "SellerLoginSuccessLimit").get("Value").toString());
			int flimit = Integer.valueOf(authWapper.getLoginSafeConfiguration("BlackList", "Ip", "SellerLoginFailLimit").get("Value").toString());
			while (!(success > slimit || failed > flimit)) {
				AuthCallService.modifyLoginPassword(String.valueOf(userid), "123456a");
				String loginid = new YmtUsersWapper().getYmtUsers(userid).getSloginid();
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(loginid);
				lab.setPas("123456a");
				lab.setClientIp(ip);
				lab.setSourceType("seller.ymatou.com");
				lac.setData(lab);
				lac.callService();
				if (lac.getSuccess()) {
					success++;
				} else {
					failed++;
				}
				userid++;
			}
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			Logger.verifyEquals("由于安全原因登录失败", lac.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	@Ignore
	public void Tc_LoginAuth_052() {
		Logger.start(false, "sellerapp账号多次同ip登入,ip加入黑名单");
		try {
			String ip = TestDataManager.getRandomIp();
			int userid = 92;
			int success = 0;
			int failed = 0;
			int slimit = Integer.valueOf(authWapper.getLoginSafeConfiguration("BlackList", "Ip", "SellerLoginSuccessLimit").get("Value").toString());
			int flimit = Integer.valueOf(authWapper.getLoginSafeConfiguration("BlackList", "Ip", "SellerLoginFailLimit").get("Value").toString());
			while (!(success > slimit || failed > flimit)) {
				AuthCallService.modifyLoginPassword(String.valueOf(userid), "123456a");
				String loginid = new YmtUsersWapper().getYmtUsers(userid).getSloginid();
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(loginid);
				lab.setPas("123456a");
				lab.setClientIp(ip);
				lab.setSourceType("seller.app.ymatou.com");
				lac.setData(lab);
				lac.callService();
				if (lac.getSuccess()) {
					success++;
				} else {
					failed++;
				}
				userid++;
			}
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			Logger.verifyEquals("由于安全原因登录失败", lac.getString("LastErrorMessage"), "验证LastErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	@Ignore
	// 手工验证，国内常用城市可以登入 换一个城市不能登入 国外换省份不能登入
	public void Tc_LoginAuth_053() {
		Logger.start(false, "sellerapp账号多次同省份ip登入,不被风控");
		try {
			List<String> ips = new ArrayList<>();
			// 福建
			ips.add("059.077.172.002");
			ips.add("059.077.176.001");
			ips.add("059.079.192.002");
			ips.add("059.079.194.002");
			// 北京
			ips.add("001.015.168.001");
			// 001.000.128.000 Thailand
			ips.add("001.000.128.001");
			// 001.000.004.000 Australia Victoria
			ips.add("001.004.000.255");
			// 001.004.000.255 Australia Australia
			ips.add("005.152.180.255");
			ips.add("172.16.1.1");
			// 005.152.180.255 Australia New South Wales
			// 国外同一个州不同城市
			// 082.199.159.255 Zurich
			// 185.002.163.255 Winterthur
			ips.add("082.199.159.255");
			ips.add("185.002.163.255");
			int userid = 92;
			AuthCallService.modifyLoginPassword(String.valueOf(userid), "123456a");
			for (String ip : ips) {
				String loginid = new YmtUsersWapper().getYmtUsers(userid).getSloginid();
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(loginid);
				lab.setPas("123456a");
				lab.setClientIp(ip);
				lab.setSourceType("seller.app.ymatou.com");
				lac.setData(lab);
				lac.callService();
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	// 配置项 <add key="Disable_Seller_LoginMail_ResTips"
	// value="邮箱禁止登录,请使用手机或用户名登录"/>
	// <add key="Disable_Seller_LoginMail" value="0"/>
	public void Tc_LoginAuth_054() {
		Logger.start(true, "商家不能使用邮箱登入");
		try {
			Logger.comment("开始登陆认证");
			String ip = TestDataManager.getRandomIp();
			lab.setLoginId("jpseller@163.com");
			lab.setPas("123456a");
			lab.setSourceType("seller.app.ymatou.com");
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
			Logger.verifyEquals("邮箱禁止登录,请使用手机或用户名登录", lac.getString("LastErrorMessage"), "验证LastErrorMessage");
			Logger.verifyEquals("-410", lac.getString("ErrorCode"), "验证ErrorCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_055() {
		Logger.start(true, "商家不能在局域网登入");
		try {
			Logger.comment("开始登陆认证");
			String ip = "192.168.1.1";
			lab.setLoginId("fayette");
			lab.setPas("123456a");
			lab.setSourceType("seller.app.ymatou.com");
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();
			String status = null;
			try {
				status = authWapper.getLoginSafeConfiguration("BlackList", "Ip", "SellerDenyLogin").get("Value").toString();
			} catch (NullPointerException e) {
				Logger.comment("没有查到SellerDenyLogin,case前置条件不成立");
			}
			if (status != null && status.equals("lan;")) {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");
				Logger.verifyEquals("100", lac.getString("ErrorCode"), "验证ErrorCode");
				String date = AuthCallService.ipAreaAuthStatus("fayette", ip, "mainsite").getReturnData();
				Logger.verifyIsContains("\"Success\":true", date, "验证认证Success");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_056() {
		Logger.start(true, "商家账号从mainsite登入,不能在局域网登入");
		try {
			Logger.comment("开始登陆认证");
			String ip = "10.110.11.12";
			lab.setLoginId("fayette");
			lab.setPas("123456a");
			lab.setSourceType("mainsite");
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();
			String status = null;
			try {
				status = authWapper.getLoginSafeConfiguration("BlackList", "Ip", "SellerDenyLogin").get("Value").toString();
			} catch (NullPointerException e) {
				Logger.comment("没有查到SellerDenyLogin,case前置条件不成立");
			}
			if (status != null && status.equals("lan;")) {
				Logger.verifyEquals(false, lac.getSuccess(), "验证Success");
				Logger.verifyIsContains("请执行身份", lac.getString("LastErrorMessage"), "验证登陆信息");
				Logger.verifyEquals("100", lac.getString("ErrorCode"), "验证ErrorCode");
				String date = AuthCallService.ipAreaAuthStatus("fayette", ip, "mainsite").getReturnData();
				Logger.verifyIsContains("\"Success\":true", date, "验证认证Success");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	// 手工验证，可能被ip风控
	public void Tc_LoginAuth_057() {
		Logger.start(true, "192.167公网网段商家可以登入");
		try {
			Logger.comment("开始登陆认证");
			String ip = "172.13.1.1";
			lab.setLoginId("fayette");
			lab.setPas("123456a");
			lab.setSourceType("seller.app.ymatou.com");
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_LoginAuth_058() {
		Logger.start(false, "解锁IP区域只解锁最近更新过的那一条,JIRACONN-1160");
		try {
			List<String> ips = new ArrayList<>();
			// 福建
			ips.add("059.077.172.002");
			// 北京
			ips.add("001.015.168.001");
			// 国外同一个州不同城市
			// 082.199.159.255 Zurich
			ips.add("082.199.159.255");
			int userid = 99;
			AuthCallService.modifyLoginPassword(String.valueOf(userid), "123456a");
			for (String ip : ips) {
				String loginid = new YmtUsersWapper().getYmtUsers(userid).getSloginid();
				lab = new LoginAuthBean();
				lac = new LoginAuthCall();
				lab.setLoginId(loginid);
				lab.setPas("123456a");
				lab.setClientIp(ip);
				lab.setSourceType("seller.app.ymatou.com");
				lac.setData(lab);
				lac.callService();
			}
			String rdata = AuthCallService.ipAreaAuthManage("China", "Beijin", "Beijin", userid).getReturnData();
			Map m = (Map) FormatUtil.GSONToObject(rdata, Map.class);
			Logger.debug(rdata);
			Logger.verifyEquals("解锁IP区域只解锁最近更新过的那一条", m.get("LastErrorMessage"), "验证LastErrorMessage");
			Logger.verifyEquals("500", m.get("ErrorCode").toString(), "验证ErrorCode");
			Logger.verifyEquals(-1d, m.get("Result"), "验证Result");
			Logger.verifyEquals("false", m.get("Success").toString(), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_059() {
		Logger.start(true, "JIRACONN-2123, ios10系统免认证");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			ULC201406Bean user = userWapper.getULCInfoByUid(UserId);
			userWapper.updatePwdByUid(UserId);
			String deviceId = TestDataManager.getRandomNum(6);
			Logger.comment("如果设备已认证过，则删除此认证数据");
			authWapper.deleteDeviceData(UserId, deviceId);
			// osversion = "ios10.x" && signVerified == 2
			Logger.comment("设置设备信息");
			SaveBean saveBean=DeviceidCallService.setDefaultFullSaveBean();
			saveBean.setDeviceid(deviceId);
			saveBean.setUserid(UserId);
			saveBean.setOsversion("ios10.1");
			DeviceidCallService.saveCall(saveBean);
			Logger.comment("登陆此用户");
			lab.setLoginId(user.getlBills().getLoginId().toLowerCase());
			lab.setPas("123456a");
			lab.setClientIp("1.1.9.1");
			lab.setSourceType("app");
			lab.setDeviceId(deviceId);
			lab.setClientId("aaaa");
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(phone, lac.getUserData().getLoginMobile(), "验证UserName");
			Logger.verifyNotNull(AccessToken, "验证AccessToken");
			Logger.verifyEquals(UserId, lac.getUserData().getUserId(), "验证UserId");
			Logger.verifyEquals(UserName.toLowerCase(), lac.getUserData().getLoginId().toLowerCase(), "验证登陆ID");
			Logger.verifyEquals(email.toLowerCase(), lac.getUserData().getLoginMail().toLowerCase(), "验证登录邮箱");
			Logger.verifyEquals(AccessToken, lac.getUserData().getSign(), "验证Token信息");
			Map<String, Object> info = authWapper.getIPAuthByUserIdAndArea(UserId, null, null, null);
			Logger.verifyEquals(String.valueOf(UserId), info.get("UserId").toString(), "验证UserId信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_060() {
		Logger.start(true, "多ip注册用户第一次在PC端登陆，登入认证成功JIRACONN-2962");
		try {
			Logger.comment("前置条件准备");
			String phone = TestDataManager.getPhoneNum();
			String email = TestDataManager.getEmail();
			String ip = TestDataManager.getRandomIp()+","+ TestDataManager.getRandomIp();
			Map UserMap = UserCallService.registerUser(email, phone, ip);
			String AccessToken = (String) UserMap.get("token");
			int UserId = (Integer) UserMap.get("userId");
			String UserName = (String) UserMap.get("loginId");
			//
			Logger.comment("开始登陆认证");
			lab.setLoginId(UserName);
			lab.setPas("123456a");
			lab.setSourceType("mainsite");
			lab.setClientIp(ip);
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(phone, lac.getUserData().getLoginMobile(), "验证UserName");
			Logger.verifyNotNull(AccessToken, "验证AccessToken");
			Logger.verifyEquals(UserId, lac.getUserData().getUserId(), "验证UserId");
			Logger.verifyEquals(UserName.toLowerCase(), lac.getUserData().getLoginId().toLowerCase(), "验证登陆ID");
			Logger.verifyEquals(email.toLowerCase(), lac.getUserData().getLoginMail().toLowerCase(), "验证登录邮箱");
			Logger.verifyEquals(AccessToken, lac.getUserData().getSign(), "验证Token信息");
			Map<String, Object> info = authWapper.getIPAuthByUserIdAndArea(UserId, null, null, null);
			Logger.verifyEquals(String.valueOf(UserId), info.get("UserId").toString(), "验证UserId信息");
			
			lab.setClientIp(ip.split(",")[0]);
			lac.callService();
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			//只关注第一个ip
//			lab.setClientIp(ip.split(",")[1]);
//			lac.callService();
//			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_LoginAuth_061() {
		Logger.start(true, "JIRACONN-17316, ios11系统免认证");
		try {
			Logger.comment("前置条件准备");

			com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean urb = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer UserId = uc.getUserid();
			String AccessToken=uc.getAccessToken();
			
			String UserName = urb.getLoginMobile();
			String ip=urb.getClientIp();
			
			String deviceId = TestDataManager.getRandomNum(6);
			Logger.comment("如果设备已认证过，则删除此认证数据");
			authWapper.deleteDeviceData(UserId, deviceId);
			// osversion = "ios10.x" && signVerified == 2
			Logger.comment("设置设备信息");
			SaveBean saveBean=DeviceidCallService.setDefaultFullSaveBean();
			saveBean.setDeviceid(deviceId);
			saveBean.setUserid(UserId);
			saveBean.setOsversion("ios11.1");
			DeviceidCallService.saveCall(saveBean);
			Logger.comment("登陆此用户");
			lab.setLoginId(urb.getLoginId());
			lab.setPas(urb.getPas());
			lab.setClientIp("1.1.9.1");
			lab.setSourceType("app");
			lab.setDeviceId(deviceId);
			lab.setClientId("aaaa");
			lac.setData(lab);
			lac.callService();
			Logger.verifyEquals(true, lac.getSuccess(), "验证Success");
			Logger.verifyEquals(urb.getLoginMobile(), lac.getUserData().getLoginMobile(), "验证UserName");
			Logger.verifyNotNull(AccessToken, "验证AccessToken");
			Logger.verifyEquals(UserId, lac.getUserData().getUserId(), "验证UserId");
			Logger.verifyEquals(urb.getLoginId(), lac.getUserData().getLoginId(), "验证登陆ID");
			Logger.verifyEquals(urb.getLoginMail(), lac.getUserData().getLoginMail(), "验证登录邮箱");
			Logger.verifyEquals(AccessToken, lac.getUserData().getSign(), "验证Token信息");
			Map<String, Object> info = authWapper.getIPAuthByUserIdAndArea(UserId, null, null, null);
			Logger.verifyEquals(String.valueOf(UserId), info.get("UserId").toString(), "验证UserId信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/**
	 * 删除Ip黑名单，删除IP在一段时间内的历史记录
	 * 
	 * @param ip
	 *            IP
	 * @param dateTime
	 *            删除此时间之后的历史记录（从现在到dateTime为止的历史记录）
	 * @throws Exception
	 */
	public void checkIpLoginHistory(String ip, String dateTime) throws Exception {
		if (DELETELOGINHISTORY) {
			ymtblacklistuserWapper.deleteData(ip);
			mloginHistoryWapper.deleteByIp(ip, dateTime);
		}
	}

	/**
	 * 删除设备黑名单，删除设备在一段时间内的历史记录
	 * 
	 * @param deviceId
	 *            设备Id
	 * @param dateTime
	 *            删除此时间之后的历史记录（从现在到dateTime为止的历史记录）
	 * @throws Exception
	 */
	public void checkDeviceLoginHistory(String deviceId, String dateTime) throws Exception {
		if (DELETELOGINHISTORY) {
			ymtblacklistuserWapper.deleteData(deviceId);
			mloginHistoryWapper.deleteByDeviceId(deviceId, dateTime);
		}
	}

	/**
	 * 删除用户黑名单，删除用户在一段时间内的登陆记录
	 * 
	 * @param uId
	 *            用户Id
	 * @param loginId
	 *            登陆Id
	 * @param dateTime
	 *            删除此时间之后的历史记录（从现在到dateTime为止的历史记录）
	 * @throws Exception
	 */
	public void checkLoginIDLoginHistory(int uId, String loginId, String dateTime) throws Exception {
		if (DELETELOGINHISTORY) {
			ymtblacklistuserWapper.deleteData(uId);
			mloginHistoryWapper.deleteByLoginId(loginId, dateTime);
		}
	}
}